package asteroids.model.expressions;

import exceptions.IllegalOperandException;

/**
 * A subclass of expression (E) that represents the subtraction (-) of two doubles
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public class Subtraction extends Operation {

	public Subtraction(E e1, E e2) {
		super(e1, e2);
	}

	@Override
	public Double getValue() throws IllegalOperandException {
		//double result = 0;
		if(this.isValidExpression() == false) { throw new IllegalOperandException(); }
		Double left = (Double)getLeftOperand().getValue();
		Double right = (Double)getRightOperand().getValue();
		return (left.doubleValue() - right.doubleValue());
	}
	
	@Override
	public String toString() {
		return getLeftOperand().toString() + " - " + getRightOperand().toString();
	}
	
	@Override
	public E createCopy() {
		return new Subtraction(getLeftOperand().createCopy(), getRightOperand().createCopy());
	}
}
